//
// transport.h
// libprotea
// Tools Library for the Protea Project / Base class for data transport services
// Copyright (C) 2003, 2004, 2005 eXegeSys, Inc.
// Copyright (C) 2008 Bruce A. James
//
// This program is part of the Protea Project.
//
// The Protea Project is free software; you can redistribute it and/or modify it 
// under the terms of the GNU General Public License as published by the 
// Free Software Foundation, either version 3 of the License, or (at your 
// option) any later version.
//
// The Protea Project is distributed in the hope that it will be useful, but 
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
// for more details.
// 
// You should have received a copy of the GNU General Public License along 
// with this program.  If not, see <http://www.gnu.org/licenses/>.
// 
// Please send correspondence to:
// 
// theproteaproject@gmail.com
//

#ifndef __PROTEA_TRANSPORT_H__
#define __PROTEA_TRANSPORT_H__

class XCAppInterface;
class XCMsgPort;

enum TransportType {
	TRANSPORT_DATA = 0,
	TRANSPORT_LISTENER = 1
};

/// Generic data transfer class
class __EXPORT XCTransport : public XCBase {
public:
	XCTransport( XCAppInterface* appowner, XCMsgPort* portowner = NULL );

	/// Send data
	virtual int Send( const void* data, int size = -1 ) = 0;

	/// Receive data
	virtual int Recv( void* data, int size ) = 0;

	/// Close connection
	virtual int Close() = 0;

	/// Cancel outstanding Async I/O requests
	virtual void CancelIO();

	/// Returns the value of the input handle
	virtual PORT_HANDLE GetInHandle() = 0;

	/// Returns the value of the output handle
	virtual PORT_HANDLE GetOutHandle() = 0;

	/// Determines whether a port is in synch or async mode
	bool			async;

	TransportType	tType;

	void SetMsgPort( XCMsgPort* port_owner );
	void SetApp( XCAppInterface* app );

protected:
	XCMsgPort* myowner;
	XCAppInterface* myapp;
};

#endif
